<?php
// 保存到数据库
date_default_timezone_set("PRC");

$dsn = "mysql:host=127.0.0.1;dbname=blog";
$db = new PDO($dsn, "root", "123456");
$db->exec("set names utf8mb4");

// 检测邮箱是否存在了。
$sql = "select * from admin where admin_email='$adminEmail'";
$statement = $db->query($sql);
if ($statement->fetch()) {
    echo $adminEmail . ' 邮箱已经存在，请输入另外的邮箱。';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}

$addTime = time();
$updateTime = $addTime;

$salt = "0w37qVYCCu#SV7s4x3ctMNwQS@&4Hc";
$adminPassword = md5($salt. md5($salt . $adminPassword . $salt) . $salt);

$sql = "insert into admin (admin_name, admin_email, admin_password, add_time, update_time) 
  values ('$adminName', '$adminEmail', '$adminPassword', '$addTime', '$updateTime')";
$result = $db->exec($sql);
//var_dump($db->errorInfo());